package com.gorkr.labuladong.data_struct.array.windows;

import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;

public class L3 {

    public int lengthOfLongestSubstring(String s) {
        if(s.length()<=1){
            return s.length();
        }

        int left = 0, right = 1;
        HashSet<Character> set = new HashSet<>();

        char[] chars = s.toCharArray();
        set.add(chars[0]);
        int max = 1;

        while(right<chars.length){
            if(!set.contains(chars[right])){
                set.add(chars[right++]);
            }else {
                set.remove(chars[left++]);
            }
            max = Math.max(max, (right - left));
        }
        return max;

    }

    @Test
    public void test(){
        String s =  "aa";
        System.out.println(lengthOfLongestSubstring(s));
}

}
